# -*-* encoding:UTF-8 -*-
# author : mengy
# date   : 2018/11/21

import socket

# 创建socket对象
s = socket.socket()
# 获取本地主机名
host = socket.gethostname()
print "主机名:",host
# 绑定端口
port = 8000
s.bind((host,port))

# 等待客户端连接
s.listen(5)
while True:
    c,address = s.accept()
    print address,""
    send_msg = ""
    flag = True
    while flag:
        if send_msg == "":
            send_msg = "欢迎"
            c.send(send_msg)
        else:
            send_msg = raw_input("请输入要发送给客户端的消息:")
            c.send(send_msg)
        recv_msg = c.recv(1024)
        print "\t来自客户端的消息:",recv_msg
        if recv_msg == 'bye':
            print "客户端已下线！"
            flag = False
    c.close()


